package test3_28.demo01;

import java.util.ArrayList;

public class Homework16_5 {
    public static void main(String[] args) {
        Student s1 = new Student("刘德华", 85);
        Student s2 = new Student("张学友", 100);
        Student s3 = new Student("刘杰", 65);
        Student s4 = new Student("章子怡", 58);
        Student s5 = new Student("周迅", 76);

        ArrayList<Student> list = new ArrayList<>();
        list.add(s1);
        list.add(s2);
        list.add(s3);
        list.add(s4);
        list.add(s5);

        //1、输出ArrayList中的对象个数。
        System.out.println("学生人数为：" + list.size() + "人");

        //2、删除姓名为“刘杰”的学生信息，并输出ArrayList中现有学生信息。
        for (int i = 0; i < list.size(); i++) {
            if(list.get(i).getName().equals("刘杰")){
                list.remove(i);
                break;
            }
        }

        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i).getName()+" "+list.get(i).getScore());
        }

        System.out.println("===========");
        //3、将姓名为“刘德华”的学生成绩改为95。
        for (int i = 0; i < list.size(); i++) {
            if(list.get(i).getName().equals("刘德华")){
                list.get(i).setScore(95);
                break;
            }
        }
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i).getName()+" "+list.get(i).getScore());
        }

        System.out.println("===========");
        //4、输出成绩不及格的学生姓名
        System.out.println("不及格的学生：");
        for (int i = 0; i < list.size(); i++) {
            if(list.get(i).getScore() < 60){
                System.out.println(list.get(i).getName());
            }
        }


    }
}
